import React, { forwardRef, useState, useImperativeHandle, useRef, useEffect } from "react";
import { Menu, Space } from '@bytedance/mona-ui';
import AddLtalp from './addLtalp'
import SetLtalp from './setLtalp'
import PrtConfigBuy from './prtConfigBuy'
import AutoListContent from "./autoListContent";
function MenuBox(props, ref) {
    const [current, setcurrent] = useState(props.actstr || 'addCoupon')
    // const [current, setcurrent] = useState('setCoupon')
    const [addConfigAllDatas, setaddConfigAllDatas] = useState<any>([])
    type ChildMethods = {
        // 子组件暴露给父组件的方法
        someMethod: () => void;
        getPrdListSkus: () => void;
        setAddpritVstatus: () => void;
        setAddActConfig: (any: any) => void;
        // setAddpritVstatus1: () => void;
    };
    type ChildAdConMethods = {
        // 子组件暴露给父组件的方法

        setAddpritVstatusAllconet: (any: any) => void;
        // setAddpritVstatus1: () => void;
    };
    const childRef = useRef<ChildMethods>(null);
    const childAdConRef = useRef<ChildAdConMethods>(null);
    function someMethod() {
        if (childRef.current) {
            childRef.current?.someMethod();
        }
    }
    useImperativeHandle(ref, () => ({
        someMethod,
    }));
    useEffect(() => {
        if (!props || !props.setFooterStatus) return
        if (current === 'addCoupon') {
            props.setFooterStatus(true)
        } else {
            props.setFooterStatus(false)

        }
    }, [current])
    function addConfigAllFun(data) {
        console.log('data', data)
        setaddConfigAllDatas([...data])
        // if (data.type === 'addConfigAll') {

        // }
    }
    return (<Space direction="vertical" className="dlyclashiden" style={{
        width: '100%'
    }} size={0}>
        <Menu style={{
            marginBottom: 10
        }} onClick={(e) => {
            // console.log('e', e)

            setcurrent(e.key)
        }} selectedKeys={[current]} mode="horizontal">
            <Menu.Item key="addCoupon">
                活动创建
            </Menu.Item>
            <Menu.Item key="addConfigBuy">
                (价格,库存,限购)配置
            </Menu.Item>
            <Menu.Item key="setCoupon">
                活动管理
            </Menu.Item>
            <Menu.Item key="setltalpList">
                自动续期活动列表
            </Menu.Item>
        </Menu>
        <div className={current === 'addCoupon' ? 'show' : 'hide'}>
            <AddLtalp ref={childRef} setcurrent={setcurrent} setcurrentAdd={(key) => {
                setcurrent(key)
                if (childAdConRef.current) {
                    console.log('childsetAddpritVstatus', childAdConRef.current)
                    childAdConRef.current?.setAddpritVstatusAllconet(true);
                }
            }} clearBox={props.clearBox} addConfigAllDatas={addConfigAllDatas} getPrdListSkus={() => {
                if (childRef.current) {
                    // console.log('childRef.curren', childRef.current)
                    childRef.current?.getPrdListSkus();
                }
            }} />
        </div>
        <div className={current === 'setCoupon' ? 'show' : 'hide'}>
            <SetLtalp />
        </div>
        <div className={current === 'addConfigBuy' ? 'show' : 'hide'}>
            <PrtConfigBuy addConfigAllFun={addConfigAllFun} ref={childAdConRef} setcurrentAddContar={(key) => {
                setcurrent(key)
                if (childRef.current) {
                    // console.log('childRef.curren', childRef.current)
                    childRef.current?.setAddActConfig(true);
                }
            }} />
        </div>
        <div className={current === 'setltalpList' ? 'show' : 'hide'}>
            <AutoListContent />
        </div>

        {/* {current === 'addCoupon' &&}
        {current === 'setCoupon' && }
        {current === 'addConfigBuy' && <PrtConfigBuy />} */}
    </Space>)
}
export default forwardRef(MenuBox)